<div class='head'>
  <div class='title'>  
    <h1>追天涯</h1>
  </div>
  <div class='tools'>
    <div class="type">
      <% form_tag '#', :id => 'search_type_form' do  %>
        <%= link_to_function "#{@hot_post_type_name}▼",
              "
              if($('hot_post_types').style.display == '') {
                  $('hot_post_types').hide();
                } else {
                  $('hot_post_types').show();
                }
              ",
              :title => "热贴分类",
              :class => 'hot_post_type'
        %>
        <%= hidden_field_tag :hot_post_type_id, params[:hot_post_type_id]   %>
        <%= radio_button_tag :search_type,'all',params[:search_type] == 'all',:id => 'search_type_all', :class => :no %>
        <%= label_tag 'search_type_all','全部' %>
        <%= radio_button_tag :search_type,'actived',params[:search_type] == 'actived',:id => 'search_type_actived', :class => :no %>
        <%= label_tag 'search_type_actived',t(:actived) %>
        <%= radio_button_tag :search_type,'capturing',params[:search_type] == 'capturing',:id => 'search_type_capturing', :class => :no %>
        <%= label_tag 'search_type_capturing', t(:capturing) %>
        <%= radio_button_tag :search_type,'end',params[:search_type] == 'end',:id => 'search_type_end', :class => :no %>
        <%= label_tag 'search_type_end', t(:end) %>
        <%= radio_button_tag :search_type,'hidden',params[:search_type] == 'hidden',:id => 'search_type_hidden', :class => :no %>
        <%= label_tag 'search_type_hidden', t(:hidden) %>
      <% end %>
    </div>
    <div class="order_by">
      <%= link_to_function( "发起时间↑",
            "order_by('created_at','desc')",
            :class => params.order_by == 'hot_posts.created_at asc' ? 'order_by h' : 'order_by' ,
            :title => '升序排序'
          ) if params.order_by == 'hot_posts.created_at asc' or  params[:order] != 'created_at' %>
      <%= link_to_function( "发起时间↓",
            "order_by('created_at','asc')",
            :class => params.order_by == 'hot_posts.created_at desc' ? 'order_by h' : 'order_by' ,
            :title => '降序排序'
          )  if params.order_by == 'hot_posts.created_at desc' %>
      <%= link_to_function( "追踪时间↑",
            "order_by('updated_at','desc')",
            :class => params.order_by == 'hot_posts.updated_at asc' ? 'order_by h' : 'order_by' ,
            :title => '升序排序'
          ) if params.order_by == 'hot_posts.updated_at asc' or  params[:order] != 'updated_at' %>
      <%= link_to_function( "追踪时间↓",
            "order_by('updated_at','asc')",
            :class => params.order_by == 'hot_posts.updated_at desc' ? 'order_by h' : 'order_by' ,
            :title => '降序排序'
          )  if params.order_by == 'hot_posts.updated_at desc' %>
      <%= link_to_function( "发表时间↑",
            "order_by('first_released_at','desc')",
            :class => params.order_by == 'hot_posts.first_released_at asc' ? 'order_by h' : 'order_by' ,
            :title => '升序排序'
          ) if params.order_by == 'hot_posts.first_released_at asc' or  params[:order] != 'first_released_at' %>
      <%= link_to_function( "发表时间↓",
            "order_by('first_released_at','asc')",
            :class => params.order_by == 'hot_posts.first_released_at desc' ? 'order_by h' : 'order_by' ,
            :title => '降序排序'
          )  if params.order_by == 'hot_posts.first_released_at desc' %>
    </div>
    <div id="hot_post_types" style='display:none;'>
      <div>
        <%= link_to_function "全部【#{@hot_post_types.hot_posts_count}】",
              "$('hot_post_type_id').value = '';$('hot_post_types').hide()",
              :title => "共有#{@hot_post_types.hot_posts_count}帖",
              :class => "hot_post_type #{params[:hot_post_type_id] == '%' ? 'h' : ''}"
         %>
      </div>
    <% @hot_post_types.each do |type|  %>
      <div>
        <%= link_to_function "#{type.name}【#{type.hot_posts_count}】",
              "$('hot_post_type_id').value = '#{type.id}';$('hot_post_types').hide()",
              :title => "共有#{type.hot_posts_count}帖",
              :class => "hot_post_type #{params[:hot_post_type_id] == type.id.to_s ? 'h' : ''}"
         %>
      </div>
    <% end %>
    </div>
  </div>
</div>
<div class='hot_posts'>
  <div class='tip'>
    <div class='info'>
      共<b><%= @hot_posts.total_entries %></b>贴
    </div>
    <div class='will_paginate'>
      <%= remote_will_paginate @hot_posts %>
    </div>    
  </div>
  <% @hot_posts.each do |hot_post| %>
  <div id='hot_post_<%= hot_post.id %>' class='hot_post <%= cycle '','h' %>'>
    <div class='line'>
      <div class='logo'>
        <%= user_logo_image_tag hot_post.user,:width => 70, :title => "#{hot_post.user.nick_name}于#{time_ago_in_words hot_post.created_at,false}前起追" %>
      </div>
      <div class='title'>
          <b>『<%= hot_post.hot_post_type.name %>』</b>
          <%= link_to hot_post.title, tools_zhui_tian_ya_hot_post_url(hot_post),:target => :_blank, :title => hot_post.title %>
      </div>
      <div class='info'>
        <div class='others'>
          <dl>
            <dt>来自：</dt>
            <dd>天涯社区</dd>
          </dl>
          <dl>
            <dt>作者：</dt>
            <dd><%= hot_post.author %></dd>
          </dl>
          <dl class="l">
            <dd>首次发表于<%= time_ago_in_words hot_post.first_released_at,false %>前</dd>
          </dl>
          <% if hot_post.the_last_lz_sub_hot_post %>
          <dl class="l">
            <dd>最后更新于<%= time_ago_in_words hot_post.the_last_lz_sub_hot_post.released_at,false %>前</dd>
          </dl>          
          <% end %>
        </div>
      </div>
      <div class='stat'>
        <dl>
          <dt>
            正在追：
          </dt>
          <dd>
            <b><%= hot_post.be_zhuied.size %></b>人
          </dd>
        </dl>
        <dl>
          <dt>
            曾经追：
          </dt>
          <dd>
            <b class="l"><%= hot_post.had_been_zhuied.size %></b>人
          </dd>
        </dl>
        <dl>
          <dt>
            楼主：
          </dt>
          <dd><b><%= hot_post.lz_sub_hot_posts_count %></b>贴</dd>
        </dl>
        <dl>
          <dt>
            跟帖：
          </dt>
          <dd><b class="l"><%= hot_post.sub_hot_posts_count %></b>贴</dd>
        </dl>
      </div>
      <div class='status'>
        <dl>
          <dt>
            状态：
          </dt>
          <dd>
            <b id="hot_post_status_<%= hot_post.id %>" class="<%= hot_post.status %>"><%= t hot_post.status %></b>
            <%= link_to_remote( image_tag('others/refresh.png',:size => '12x12'),
                  :url => reactive_hot_post_url(hot_post),
                  :method => :put,
                  :loading => "
                    $('hot_post_status_#{hot_post.id}').className='actived';
                    $('hot_post_status_#{hot_post.id}').update('#{t :actived}');
                    $('hot_post_reactive_#{hot_post.id}').hide();
                    $('hot_post_end_#{hot_post.id}').show()",
                  :html => {
                    :class => :reactive,
                    :title => '重新激活，继续被追',
                    :id => "hot_post_reactive_#{hot_post.id}",
                    :style => hot_post.status.actived? ? 'display:none':''
                  }
             )
             %>
            <%= link_to_remote( image_tag('others/freelance.png',:size => '12x12'),
                  :url => to_be_end_hot_post_url(hot_post),
                  :method => :put,
                  :loading => "
                    $('hot_post_status_#{hot_post.id}').className='end';
                    $('hot_post_status_#{hot_post.id}').update('#{t :end}');
                    $('hot_post_reactive_#{hot_post.id}').show();
                    $('hot_post_end_#{hot_post.id}').hide()",
                  :html => {
                    :class => :end,
                    :title => '设置为完结，将不再被追',
                    :id => "hot_post_end_#{hot_post.id}",
                    :style => hot_post.status.actived? ? "":"display:none"
                  }
             ) 
             %>
          </dd>
        </dl>
        <dl>
          <dt>
            尝试：
          </dt>
          <dd>
            <%= hot_post.trying_count %>次
          </dd>
        </dl>
        <dl class="l">
          <dd>
            最后一次追踪于<%= time_ago_in_words hot_post.updated_at,false %>前
          </dd>
        </dl>
      </div>
      <div class='tools'>
        <div>
          <%= link_to_function "查看lz新帖", "show_or_hide_the_lz_last_post(this,'hot_post_#{hot_post.id}_lz_last_post')" %>
        </div>
        <%  if hot_post.the_last_error.present? %>
        <div>
          <%= link_to_function "查看异常", "show_or_hide_the_last_error(this,'hot_post_#{hot_post.id}_error')" %>
        </div>
        <% end %>
        <div>
          <%= link_to_function "谁在追贴", "show_or_hide_zhuiers(this,'hot_post_#{hot_post.id}_zhuiers')", :title => "#{hot_post.be_zhuied.size}人在追，#{hot_post.had_been_zhuied.size}人曾经追过" %>
        </div>
      </div>
    </div>
    <div id="hot_post_<%= hot_post.id %>_error" class="line corner the_last_error" style="display:none">
      <% if hot_post.the_last_error.present? %>
      <%= hot_post.the_last_error %>
      <% else %>
      <div class="no_error">
        无异常!
      </div>
      <% end %>
    </div>
    <div id="hot_post_<%= hot_post.id %>_lz_last_post" class="line corner lz_last_post" style="display:none">
      <% if hot_post.the_last_lz_sub_hot_post %>
      <div class="head">发表日期：<%= hot_post.the_last_lz_sub_hot_post.released_at %></div>
      <div class='page'>
        <div class='left'>
          共<b><%= hot_post.lz_sub_hot_posts_count %></b>贴,当前第<b class='l'><%= hot_post.lz_sub_hot_posts_count %></b>贴
        </div>
        <div class='right'>
          <%= link_to_remote '前一帖',
              :update => "hot_post_#{hot_post.id}_lz_last_post",
              :url => pre_lz_post_hot_post_url(hot_post.the_last_lz_sub_hot_post),
              :method => :get,
              :loading => nano_loading("hot_post_#{hot_post.id}_pre_lz_post",:only_img => true),
              :html => {
                :id => "hot_post_#{hot_post.id}_pre_lz_post"
              } if hot_post.lz_sub_hot_posts_count > 1
          %>
        </div>
      </div>
      <div class="content">
        <%= hot_post.the_last_lz_sub_hot_post.content %>
      </div>
      <% else %>
      <div class="head">
        无
      </div>
      <% end %>
    </div>
    <div id="hot_post_<%= hot_post.id %>_zhuiers" class="line corner zhuiers" style="display:none">
      <% if hot_post.be_zhuied.any? %>
      <div class='head'>
        <b><%= hot_post.be_zhuied.size %></b>人正在追
      </div>
      <div class='body'>
        <% hot_post.be_zhuied.each do |setting| %>
          <div class='logo'>
            <%= user_logo_image_tag setting.user,:width => 50, :title => "#{setting.user.nick_name}于#{time_ago_in_words setting.created_at,false}前起追,到目前为止阅读了#{setting.scope.lz? ? '楼主' : '所有贴'}的#{number_with_precision setting.read_schedule_percent, :precision => 2}%" %>
          </div>
        <% end %>
      </div>
      <% end %>
      <% if hot_post.had_been_zhuied.any? %>
      <div class='head'>
        有<b><%= hot_post.had_been_zhuied.size %></b>人曾经追过
      </div>
      <div class='body'>
        <% hot_post.had_been_zhuied.each do |setting| %>
          <div class='logo'>
            <%= user_logo_image_tag setting.user,:width => 50, :title => "#{setting.user.nick_name}于#{time_ago_in_words setting.updated_at,false}前放弃,到目前为止阅读了#{setting.scope.lz? ? '楼主' : '所有'}贴的#{number_with_precision setting.read_schedule_percent, :precision => 2}%" %>
          </div>
        <% end %>
      </div>
      <% end %>
    </div>
  </div>
  <% end %>
  <% if @hot_posts.empty? %>
  <div id="no_record">无记录！</div>
  <% end %>
  <div class='tip bottom'>
    <div class='info'>
      共<b><%= @hot_posts.total_entries %></b>贴
    </div>
    <div class='will_paginate'>
      <%= remote_will_paginate @hot_posts %>
    </div>
  </div>
</div>
<%= observe_form :search_type_form,
      :function => "searching()",
      :frequency => 0.5
  %>